// vim:sw=4:ai:aw
#pragma once
#ifndef	__asserts_h__
#define	__asserts_h__

#ident	"@(#)asserts.h	2.3	AKK/CII	2008/02/20 20:14:15"

/** @file asserts.h
 * This file defines various macro's that can be used as checks in your program.
 * <b>NOTE</b>: It relies on the __FILE__, __LINE__ and __PRETTY_FUNCTION__
 * compiler magics to actually identify lines of source code.
 * <br>If your compiler does not provide the __PRETTY_FUNCTION__ magic,
 * simply \#define it as 0 and the asserts function will ignore that parameter.
 *
 * @author R.A.Akkersdijk@saxion.nl
 * @version 2.3 08/02/20 20:14:15
 */


#ifdef	__cplusplus
extern	"C" {
#endif

/** @internal
 * This "secret" function asserts that some boolean 'outcome' is true,
 * otherwise it will terminate the program,
 * reporting a violation, mentioning the source file, linenumber and function,
 * the violation type and the actual expression.
 */
extern void	asserts( const char * file, const int line, const char * func,
			 const int outcome,
			 const char * type, const char * expr );

/** Verify whether a precondition is met;
 * Abort the program if the condition is violated. */
#define	require(condition)\
	asserts(__FILE__,__LINE__,__PRETTY_FUNCTION__,condition,"require",#condition)

/** Verify an internal consistenty check, for instance an invariant;
 * Abort the program if the condition is violated. */
#define	check(condition)\
	asserts(__FILE__,__LINE__,__PRETTY_FUNCTION__,condition,"check",#condition)

/** Verify whether a postcondition is met;
 * Abort the program if the condition is violated. */
#define	ensure(condition)\
	asserts(__FILE__,__LINE__,__PRETTY_FUNCTION__,condition,"ensure",#condition)

/** Verify that this line of code is not reached;
 * Abort the program when this line is reached. */
#define	notreached()\
	asserts(__FILE__,__LINE__,__PRETTY_FUNCTION__,0,"notreached","")

#ifdef	__cplusplus
}
#endif

#endif	/*asserts_h*/
